<script lang="ts" setup>
import { ref } from 'vue'
import Bus from '@/utils/bus'

const props = defineProps({
  mapRef: {
    type: Object,
    default: () => {},
  },
})

const emits = defineEmits([])

const status = reactive({
  show: false,
  text: '',
  submit: false,
  deletePipe: false,
  drawPolygon: false,
  drawPolygonRange: false,
})

function addEvent() {
  Bus.$on('showPromot', ({ show, text, submit, deletePipe, drawPolygon, drawPolygonRange }) => {
    // console.log('showPromot', show, text)
    status.show = show
    status.text = text
    status.submit = submit
    status.deletePipe = deletePipe
    status.drawPolygon = drawPolygon
    status.drawPolygonRange = drawPolygonRange
  })
}

function onSubmit() {
  if (status.drawPolygon) {
    props.mapRef.submitPolygon()
  }
  else if (status.drawPolygonRange) {
    props.mapRef.submitPolygonRange()
  }
  else {
    props.mapRef.submitPipeline()
  }
  status.show = false
}

function onCancel() {
  if (status.drawPolygon) {
    props.mapRef.cancelDrawPolygon()
  }
  else if (status.drawPolygonRange) {
    props.mapRef.cancelDrawPolygonRange()
  }
  else {
    props.mapRef.cancelPipeline()
  }
  status.show = false
}

function onDeletePipe() {
  props.mapRef.onDeletePipe()
}

onMounted(() => {
  addEvent()
})
</script>

<template>
  <div v-if="status.show" class="wrap">
    <div v-if="status.deletePipe" class="submit">
      <div class="pipe-delete" @click="onDeletePipe">
        删除
      </div>
    </div>
    <div v-else-if="status.submit" class="submit">
      <div class="item submit-off" @click="onCancel">
        取消
      </div>
      <div class="item submit-on" @click="onSubmit">
        提交
      </div>
    </div>
    <div v-else>
      {{ status.text }}
    </div>
  </div>
</template>

<style scoped lang="less">
.submit {
  width: 100%;
  display: flex;
  justify-content: space-around;

  .pipe-delete {
    width: 320px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    box-shadow: 0px 2px 3px 0px #f9f8f8;
    border-radius: 5px;
    background: #0070bc;
    color: #fff;
  }

  .item {
    width: 160px;
    height: 32px;
    line-height: 32px;
    background: #fff;
    text-align: center;
    box-shadow: 0px 2px 3px 0px #f9f8f8;
    border-radius: 5px;
  }
}
.submit-off {
}
.submit-on {
  background: #0070bc !important;
  color: #fff !important;
}
.wrap {
  position: absolute;
  width: 100%;
  background-color: #eff7fc;
  color: #0070bc;
  height: 50px;
  bottom: 3px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  box-sizing: border-box;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 13px;
}
</style>
